package com.fuluwa.domain.bank.model;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fuluwa.domain.security.model.User;
import com.fuluwa.domain.shared.AbstractIdDomainObject;

/**
 * Define the transaction log, for reversal
 * @author yongxia
 *
 */
@Entity
@Table(name = "b_txn_log")
public class TransactionLog extends AbstractIdDomainObject{
	public static enum TransactionType {
		DEPOSIT, WITHDRAWL,FUNDXFER
	}
	
	@ManyToOne
	@JoinColumn(name = "cod_acct")
	private Account account;
	
	@ManyToOne
	@JoinColumn(name = "cod_user")
	private User user;
	
	private String referenceNo;
	
	private String referenceUserNo;
	
	private String txnDesc;
//	private String errorCode;
//	private String channel;

	@Enumerated(EnumType.STRING)
	private TransactionType transactionType;

	@Column(name = "amount", columnDefinition = "decimal(13,2)")
	private BigDecimal amount;
	private Bank bank = Bank.getDefaultBank();
	@Temporal(TemporalType.DATE)
	@Column(name = "dat_post")
	private Date postDate = new Date();

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "tim_post")
	private Date postTime = new Date();

	public TransactionLog(Account account, String referenceNo, String referenceUserNo, String txnDesc,
			TransactionType transactionType, BigDecimal amount) {
		this.account = account;
		this.referenceNo = referenceNo;
		this.referenceUserNo = referenceUserNo;
		this.txnDesc = txnDesc;
		this.transactionType = transactionType;
		this.amount = amount;
		this.user=account.getUser();
	}

	public Account getAccount() {
		return account;
	}

	public User getUser() {
		return user;
	}

	public String getReferenceNo() {
		return referenceNo;
	}

	public String getReferenceUserNo() {
		return referenceUserNo;
	}

	public String getTxnDesc() {
		return txnDesc;
	}

	public TransactionType getTransactionType() {
		return transactionType;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public Bank getBank() {
		return bank;
	}

	public Date getPostDate() {
		return postDate;
	}

	public Date getPostTime() {
		return postTime;
	}
	
	
	
}
